package com.lakeworks.processor;

import com.lakeworks.common.domain.ticket.TktTicket;
import com.lakeworks.common.enums.ticket.NodeType;
import com.lakeworks.decision.UpdateTicketDecision;
import com.lakeworks.decision.base.Decision;
import com.lakeworks.domain.TktProcess;
import com.lakeworks.event.NotreachedEvent;
import com.lakeworks.processor.base.AbstractTicketProcessor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class NotreachedProcessor extends AbstractTicketProcessor<NotreachedEvent> {

    @Override
    public TktProcess apply(
            NotreachedEvent event
    ) {
        String num = null;
        var process = super.apply(event);
        TktTicket ticket = event.getTicket();
        if(NodeType.QUANTITY_MISMATCH_ONE.equals(ticket.getNodeId())
                || NodeType.MAJOR_RISK_ONE.equals(ticket.getNodeId())){
            ticket.setNodeId(NodeType.QUANTITY_MISMATCH_THREE.getValue());
            num = "一";
        }else {
            ticket.setNodeId(NodeType.QUANTITY_MISMATCH_FOUR.getValue());
            num = "二";
        }
        process.setTicketId(event.getTicketId());
        process.setComment("工厂:【第"+num+"次联系不上】");
        process.setRemark(event.getRemark());
        List<Decision> list = new ArrayList<>();
        //添加向平台推送工单信息决策
        list.add(new UpdateTicketDecision(event.getTicket(),event.getOperator()));
        process.setDecisions(list);
        return process;
    }

}
